package com.manager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.bean.EmployeeBean;
import com.dao.EmployeeDAO;
import com.dao.LeaveInfoDAO;
import com.exception.LMSException;
import com.interfaces.EmployeeManager;
import com.view.LeaveDetailView;

/**
 * The Class EmployeeManagerImpl.
 * 
 * @author : gbs02399 Created on : Jul 6, 2012 Project : LMS File Name :
 *         EmployeeManagerImpl.java
 */
public class EmployeeManagerImpl implements EmployeeManager {

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.interfaces.EmployeeManager#getEmployee(java.lang.String,
	 * java.lang.String)
	 */
	@Override
	public EmployeeBean getEmployee(final String userID, final String password)
			throws LMSException {
		return EmployeeDAO.getEmployeeBean(userID, password);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.interfaces.EmployeeManager#getEmployeeLeaveDetail(java.lang.String)
	 */
	@Override
	public LeaveDetailView getEmployeeLeaveDetail(final String userId)
			throws LMSException {
		final LeaveDetailView detailView = new LeaveDetailView();
		final EmployeeBean bean = EmployeeDAO.getEmployeeBean(userId, null);
		final HashMap<String, String> leaveInfoMap = LeaveInfoDAO
				.getEmployeeLeaveInfo(bean.getEmpId().toString());
		detailView.setLeaveId(leaveInfoMap.get("LEAVE_ID"));
		detailView.setUserId(userId);
		detailView.setUserName(bean.getEmpName());
		detailView.setCasualLeaveCount(leaveInfoMap.get("CL_BALANCE"));
		detailView.setEarnedLeaveCount(leaveInfoMap.get("EL_BALANCE"));
		detailView.setSickLeaveCount(leaveInfoMap.get("SL_BALANCE"));
		return detailView;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.interfaces.EmployeeManager#insertEmployee(com.bean.EmployeeBean)
	 */
	@Override
	public void insertEmployee(final EmployeeBean employeeBean)
			throws LMSException {
		EmployeeDAO.insertEmployee(employeeBean);
	}
	
	public List<EmployeeBean> getEmployeeList (String userId) throws LMSException{
		List<EmployeeBean> list = new ArrayList<EmployeeBean>();
		EmployeeBean employee = getEmployee(userId, null);
		if(employee.getEmpRole().equals("N")){
			list.add(employee);
		}else{
			list = EmployeeDAO.listOfEmployees();
		}
		return list;
	}
	
	public EmployeeBean getEmployeeBean(final String empId) throws LMSException{
		return EmployeeDAO.getEmployeeBean(empId);
	}
}
